package com.rupertjones.globalcron.util;

import org.springframework.security.authentication.dao.SystemWideSaltSource;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;

/**
 * <p>&copy Rupert Jones 2012</p>
 *
 * @author rup
 */
public class SecretEncoder {

    private static final String SALT =
            "There is an idea of a Patrick Bateman; some "
            + "kind of abstraction. But there is no real me: only an entity, something "
            + "illusory. And though I can hide my cold gaze, and you can shake my hand "
            + "and feel flesh gripping yours and maybe you can even sense our lifestyles "
            + "are probably comparable... I simply am not there.";
            // from American Psycho - by Bret Easton Ellis - Vintage Books - 1991.

    private static final ShaPasswordEncoder ENCODER = new ShaPasswordEncoder(256);

    private static final SystemWideSaltSource SALT_SOURCE = new SystemWideSaltSource();

    private static final int ITERATIONS = 1000;

    static {
        SALT_SOURCE.setSystemWideSalt(SALT);
        ENCODER.setIterations(ITERATIONS);
        ENCODER.setEncodeHashAsBase64(false);
    }

    public static String hash(String input) {
        return ENCODER.encodePassword(input, SALT_SOURCE.getSystemWideSalt());
    }
}
